package com.sykj.springboot.test.designMode.Observer3;

import java.util.ArrayList;
import java.util.List;

public class Hanfeizi implements Observable {

    List<Observer> list = new ArrayList<>();


    public void haveBreakFast() {
        System.out.println("韩非子：开始吃早饭");
        notifyObserver("韩非子开始吃早饭了");
    }

    public void haveFun() {
        System.out.println("韩非子：开始娱乐了");
        notifyObserver("韩非子开始娱乐了");
    }

    @Override
    public void addObserver(Observer obs) {
        list.add(obs);
    }

    @Override
    public void delObserver(Observer obs) {
        list.remove(obs);
    }

    @Override
    public void notifyObserver(String context) {
        list.forEach(obs->obs.update(context));
    }




}
